package demo3;

import java.util.Stack;

public class Test2 {
    public static void main(String[] args) {
        int[] pushA = {1,2,3,4,5};
        int[] popA = {5,4,3,2,1};
        Stack<Integer> stack = new Stack<>();
        int j = 0;
        for (int i = 0; i < pushA.length; i++) {
            stack.push(pushA[i]);
            while (j < popA.length && !stack.isEmpty()) {
                if (stack.peek() == popA[j]) {
                    stack.pop();
                    j++;
                }
            }
        }
        if (!stack.isEmpty() || j < popA.length) {
            //return false;
        }
        //return true;
    }
}
